package com.newcapec.modules.health.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.newcapec.common.utils.DateUtils;
import com.newcapec.common.utils.PageUtils;
import com.newcapec.common.utils.Query;
import com.newcapec.modules.health.dao.UserUpdataInfoDao;
import com.newcapec.modules.health.entity.SchoolUpdateInfoVo;
import com.newcapec.modules.health.entity.UserUpdataInfoEntity;
import com.newcapec.modules.health.entity.UserUpdataInfoVo;
import com.newcapec.modules.health.service.UserUpdataInfoService;
import com.newcapec.modules.health.vo.ProvinceHealthVo;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


@Service("userUpdataInfoService")
public class UserUpdataInfoServiceImpl extends ServiceImpl<UserUpdataInfoDao, UserUpdataInfoEntity> implements UserUpdataInfoService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String stuNo = (String)params.get("stuNo");
        Date  begin= DateUtils.stringToDate((String) params.get("beginTime"), DateUtils.DATE_TIME_PATTERN);
        Date  end= DateUtils.stringToDate((String) params.get("endTime"), DateUtils.DATE_TIME_PATTERN);
        IPage<UserUpdataInfoEntity> page = this.page(
                new Query<UserUpdataInfoEntity>().getPage(params, "create_time", false),
                new QueryWrapper<UserUpdataInfoEntity>()
                        .eq(StringUtils.isNotBlank(stuNo),"stu_no", stuNo)
                        .between(begin!=null && end!=null,"create_time",begin,end)
        );

        return new PageUtils(page);
    }


    public PageUtils queryListPage(Map<String,Object> params){

        IPage<SchoolUpdateInfoVo> page = this.baseMapper.selectSchoolUpdateInfo(
                new Query<SchoolUpdateInfoVo>().getPage(params), params
        );

        return new PageUtils(page);

    }

    @Override
    public  List<ProvinceHealthVo> selectProvinceHealthVo(String date, Integer healthType) {
        List<ProvinceHealthVo> list = this.baseMapper.selectProvinceHealthVo( date, healthType);
        List<ProvinceHealthVo> newList = list.stream().map(data->{
            String province = data.getProvince().replaceAll("\"","");

            data.setProvince(province.replace("省",""));
            return data;
        }).collect(Collectors.toList());
        return newList;
    }

    @Override
    public List<UserUpdataInfoVo> selectSchoolUpdateInfoByStuNo(String stuNo) {
        return this.baseMapper.selectSchoolUpdateInfoByStuNo(stuNo);
    }

    @Override
    public List<UserUpdataInfoEntity> getStuInfoByStuNo(String stuNo) {
        return this.baseMapper.getStuInfoByStuNo(stuNo);
    }
}
